<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

  <xi:include href="master.html" />

<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
  <title>MunkiReport</title>
</head>

<body>

<h1 py:content="client.name">Name</h1>


<table class="twocol">
  <tbody>
    <td>
      <h2>Machine</h2>

      <table class="client_info">
        <tbody>
          <tr>
            <th>MAC:</th>
            <td py:content="client.mac">MAC</td>
          </tr>
          <tr>
            <th>Remote IP:</th>
            <td py:content="client.remote_ip">IP</td>
          </tr>
          <py:if test="'MachineInfo' in report">
            <tr>
              <th>Hostname:</th>
              <td>${report.MachineInfo.get("hostname", "?")}</td>
            </tr>
            <tr>
              <th>OS:</th>
              <td>${report.MachineInfo.get("os_vers", "?")} (${report.MachineInfo.get("arch", "?")})</td>
            </tr>
          </py:if>
          <tr>
            <th>Free Disk Space:</th>
            <td>${report.AvailableDiskSpace / 1000000} GB</td>
          </tr>
          <tr>
            <th>Console User:</th>
            <td>${report.ConsoleUser}</td>
          </tr>
        </tbody>
      </table>
    </td>
    <td>
      <h2>Munki</h2>

      <table class="client_info">
        <tbody>
          <tr>
            <th>Version:</th>
            <td py:content="report.ManagedInstallVersion">Munki version</td>
          </tr>
          <py:if test="'ManifestName' in report">
            <tr>
              <th>Manifest:</th>
              <td py:content="report.ManifestName">Manifest name</td>
            </tr>
          </py:if>
          <tr>
            <th>Run Type:</th>
            <td py:content="report.RunType">Start time</td>
          </tr>
          <tr>
            <th>Start:</th>
            <td py:content="report.StartTime">Start time</td>
          </tr>
          <tr>
            <th>End:</th>
            <td py:content="report.EndTime">End time</td>
          </tr>
        </tbody>
      </table>
    </td>
  </tbody>
</table>


<a name="errors">&nbsp;</a>
<h2>Errors &amp; Warnings</h2>

<py:choose test="'Errors' in report or 'Warnings' in report">
  <py:when test="True">
    <py:if test="report.Errors"><pre class="error">${"\n".join(report.Errors)}</pre></py:if>
    <py:if test="report.Warnings"><pre class="warning">${"\n".join(report.Warnings)}</pre></py:if>
  </py:when>
  <py:otherwise>
    <p><i>No errors or warnings</i></p>
  </py:otherwise>
</py:choose>


<!--! Package tables -->
<py:def function="pkgtable(title, report_key)">
  <h2>${title}</h2>
  
  <py:choose test="report_key in report and len(report[report_key])">
    <py:when test="0">
      <p><i>No ${title.lower()}.</i></p>
    </py:when>
    <py:otherwise>
      <table class="client_info">
        <thead>
          <tr>
            <th>Name</th>
            <th>Size</th>
            <th>Status</th>
          </tr>
        </thead>
        <tbody>
          <tr py:for="item in report[report_key]">
            <td>
              ${item.display_name if "display_name" in item and item.display_name else item.name}
              ${item.version_to_install if "version_to_install" in item else ""}
              ${item.installed_version if "installed_version" in item else ""}
            </td>
            <td style="text-align: right;">${item.installed_size / 1000 if "installed_size" in item else "?"} MB</td>
            <td>${item.install_result if "install_result" in item else "installed" if item.installed else "not installed"}</td>
          </tr>
        </tbody>
      </table>
    </py:otherwise>
  </py:choose>
</py:def>


${pkgtable('Apple Updates', 'AppleUpdateList')}
${pkgtable('Active Installs', 'ItemsToInstall')}
${pkgtable('Active Removals', 'ItemsToRemove')}
${pkgtable('Problem Installs', 'ProblemInstalls')}


<table class="twocol">
  <tbody>
    <td>

${pkgtable('Managed Installs', 'ManagedInstalls')}

    </td>
    <td>
    
<py:if test="'RemovedItems' in report">
  <h2>Managed Uninstalls</h2>

  <table class="client_info">
    <thead>
      <tr>
        <th>Name</th>
      </tr>
    </thead>
    <tbody>
      <tr py:for="item in report.RemovedItems">
        <td>
          ${item}
        </td>
      </tr>
    </tbody>
  </table>
</py:if>

    </td>
  </tbody>
</table>

<!--! test code below -->

<?python
    import pprint
    if True:
        for k in ("MachineInfo",
                  "ConsoleUser",
                  "AvailableDiskSpace",
                  "ManagedInstallVersion",
                  "ManifestName",
                  "RunType",
                  "StartTime",
                  "EndTime",
                  "Errors",
                  "Warnings",
                  "InstallResults",
                  "ItemsToInstall",
                  "ItemsToRemove",
                  "RemovalResults",
                  "ManagedInstalls",
                  "RemovedItems",
                  "ProblemInstalls",
                  'AppleUpdateList',
                  'InstalledItems',
                  'RestartRequired',
                  'managed_installs_list',
                  'managed_uninstalls_list',
                  'managed_updates_list'):
            try:
                del report[k]
            except:
                pass
    pretty_report = pprint.pformat(report)
?>
<py:if test="report">
  <h2>Debug</h2>
  <pre py:content="pretty_report">
    report
  </pre>
</py:if>

</body>
</html>
